<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	卡券领取记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$return['status']=array(
	'0'=>'未使用',
	'1'=>'已使用'
);
$return['cards']=pdo_getall('core_card',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	//卡券ID
	if(!empty($_RQ['card_id'])){
		$params['card_id']=intval($_RQ['card_id']);
		$return['params']['card_id']=$_RQ['card_id'];
	}
	//会员ID
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if($_RQ['createtime']){
		$time_range=cfc('tools')->base64_decode($_RQ['createtime'],$_SESSION['base_key_str']);
		$time_range=json_decode($time_range,true);
		$return['params']['createtime']=$time_range;
		$params['createtime between']=array($time_range['tstart'],$time_range['tend']);
	}
	$orderby='id asc';
	$list=pdo_getslice('core_card_log',$params,array($pindex,$psize),$total,array('mid','card_id','code','status','createtime','plugin','remark'),'',$orderby);
	if($list){
		foreach($list as &$log){
			$log['createtime']=date('y/m/d H:i:s',$log['createtime']);
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$return['htmls']=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'卡券领取记录'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'card_id','title'=>'卡券id','type'=>'string'),
			array('name'=>'mid','title'=>'会员id','type'=>'string'),
			array('name'=>'code','title'=>'兑换码','type'=>'string'),
			array('name'=>'status','title'=>'是否使用','type'=>'radio','options'=>'status'),
			array('name'=>'plugin','title'=>'插件','type'=>'string'),
			array('name'=>'remark','title'=>'备注','type'=>'string'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'string'),
		)),
		'search'=>array(
			'0'=>array('type'=>'radio','title'=>'是否使用','name'=>'status','options'=>'status'),
			'1'=>array('type'=>'string','title'=>'卡券id','name'=>'card_id'),
			'2'=>array('type'=>'string','title'=>'会员id','name'=>'mid'),
			'3'=>array('type'=>'time_range','title'=>'创建时间','name'=>'createtime','help'=>''),
		),
	);
	exi($return);